import { connect } from 'dva';
import withRouter from 'umi/withRouter';
import { ActivityIndicator } from 'antd-mobile';
import { config } from 'utils';
import Footer from './footer';

import styles from './style.less';

function BasicLayout(props) {
  const { children, location, app } = props;
  const { loading } = app;

  // 登陆页面
  if (location.pathname === '/login') {
    return (
      <div className={styles.page}>
        <div className={styles.normal}>{props.children}</div>
      </div>
    );
  }
  if (config.layoutPage.includes(location.pathname)) {
    return (
      <div className={styles.page}>
        <div className={styles.layout}>
          <div className={styles.content}>{children}</div>
          <Footer pathname={location.pathname} />
          <ActivityIndicator toast text="加载中..." animating={loading} />
        </div>
      </div>
    );
  }
  return (
    <div className={styles.page}>
      <div className={styles.normal}>{children}</div>
    </div>
  );
}

export default withRouter(connect(({ app }) => ({ app }))(BasicLayout));
